<?php
/**
* All ModelManagers intended for use with Scribble should extend this base class.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\ModelManager;
class ScribbleModelManager extends ModelManager {

	/**
	* Sets the GUID on a new model before it is saved. Rather than checking if the
	* $model is in the database, we instead have to simply check if the PK is
	* empty or not. This is to allow the developer the chance to specify their own
	* PK value (for instance, if using natural PKs - as used by the Tag model).
	*
	* @param Buan\Model Model to be saved
	* @return bool
	*/
	public function save($model) {
		if($model->getPrimaryKeyValue()=='') {
			$model->setPrimaryKeyValue(scribble_guid());
		}
		return parent::save($model);
	}
}
?>